namespace Library
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    [ToolboxBitmap(typeof(Led))]
    public class Led : Control
    {
        private bool _bHaveAction = false;
        private Color _centerColor = Color.White;
        private Color _fillColor = Color.Green;
        private string _ledName = null;
        private Color _newFillColor = Color.Red;
        private Color _oldFillColor = Color.DarkGray;
        private IContainer components = null;

        public Led()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            Graphics graphics = pe.Graphics;
            GraphicsPath path = new GraphicsPath();
            Rectangle rect = new Rectangle(0, 0, base.ClientSize.Width - 1, base.ClientSize.Height - 1);
            path.AddEllipse(rect);
            PathGradientBrush brush = new PathGradientBrush(path);
            brush.CenterColor = this._centerColor;
            Color[] colorArray = new Color[] { this._fillColor };
            brush.SurroundColors = colorArray;
            graphics.FillPath(brush, path);
            brush.Dispose();
            path.Dispose();
            base.OnPaint(pe);
        }

        public bool bHaveAction
        {
            get
            {
                return this._bHaveAction;
            }
            set
            {
                this._bHaveAction = value;
            }
        }

        [Category("外观"), Description("中心色")]
        public Color CenterColor
        {
            get
            {
                return this._centerColor;
            }
            set
            {
                this._centerColor = value;
                base.Invalidate();
            }
        }

        [Description("填充色"), Category("外观")]
        public Color FillColor
        {
            get
            {
                return this._fillColor;
            }
            set
            {
                this._fillColor = value;
                base.Invalidate();
            }
        }

        public string LedName
        {
            get
            {
                return this._ledName;
            }
            set
            {
                this._ledName = value;
                base.Invalidate();
            }
        }

        public Color newFillColor
        {
            get
            {
                return this._newFillColor;
            }
            set
            {
                this._newFillColor = value;
            }
        }

        public Color oldFillColor
        {
            get
            {
                return this._oldFillColor;
            }
            set
            {
                this._oldFillColor = value;
            }
        }
    }
}

